package com.isoft.sjhy.interceptor;

import com.isoft.sjhy.model.Userinfo;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 2 * @Author: 郭邈
 * 3 * @Date: 2021/6/30 14:16
 * 4 * @ClassName:sjhy
 * 4 * @PACKAGE_NAME:com.isoft.sjhy.interceptor
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Userinfo userinfo= (Userinfo) request.getSession().getAttribute("user");
        if(userinfo!=null){//放行
            return true;
        }
        //如果没有登录就跳转到登录页面
        response.sendRedirect(request.getContextPath()+"/login.html");
        return false;
    }
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }


    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}

